Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allow block time offset to be negative #663

Merged
merged 4 commits into from
Sep 16, 2024

Conversation

Xanewok
Copy link
Contributor

@Xanewok Xanewok commented Sep 13, 2024

Closes #588

This uses a simple approach of first converting to i128, which we know will be lossless, to only then fallibly convert it to a smaller type of i64.

We do that for simplicity: one could convert a tuple of (sign, value) to shave some bytes and cycles but we would have to explicitly handle the case of i64::MIN (its absolute value is greater by 1 than i64::MAX), which would be a bit noisy, whereas not handling it and naively using a if sign { -1 } else { 1 } * i64::try_from(value)... would not fully handle that edge case.

I tested locally the reproduction steps from #588 and can both confirm that the error happens using the steps and the problem disappears after applying the fix here. Let me know if you feel that we should add a regression test and if so, how would you prefer to proceed with testing this.

@Xanewok Xanewok requested a review from a team September 13, 2024 12:06
Copy link

changeset-bot bot commented Sep 13, 2024

🦋 Changeset detected

Latest commit: fd26e31

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@nomicfoundation/edr Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Wodann
Copy link
Member

Wodann commented Sep 13, 2024

Yes, for bugs we always add a regression test, ideally on the EDR side, using typed method invocations. The integration test folder of the provider already has a bunch of examples.

https://github.com/NomicFoundation/edr/tree/main/crates%2Fedr_provider%2Ftests%2Fissues

@Xanewok Xanewok marked this pull request as draft September 13, 2024 13:09
@Xanewok Xanewok had a problem deploying to github-action-benchmark September 13, 2024 13:43 — with GitHub Actions Failure
@Xanewok Xanewok marked this pull request as ready for review September 13, 2024 14:02
@Xanewok
Copy link
Contributor Author

Xanewok commented Sep 13, 2024

Pushed a fix and added a regression test for this; verifying that the test fails without the fix and succeeds afterwards, so this should be ready for review now.

@Xanewok Xanewok temporarily deployed to github-action-benchmark September 13, 2024 15:45 — with GitHub Actions Inactive
Copy link
Member

@Wodann Wodann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test. LGTM

@Xanewok Xanewok added this pull request to the merge queue Sep 16, 2024
Merged via the queue into main with commit c8fbf3b Sep 16, 2024
37 checks passed
@Xanewok Xanewok deleted the fix/allow-negative-block-time-offset branch September 16, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow forking blocks with future timestamps
2 participants